﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;

namespace MidSoft.Sys.Provide
{
    public partial class Modify : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int ProvideId = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(ProvideId);
                }
            }
        }

        private void ShowInfo(int ProvideId)
        {
            ChinaSoft.BLL.BLL_tb_MidSoft_Provide bll = new ChinaSoft.BLL.BLL_tb_MidSoft_Provide();
            ChinaSoft.Model.Model_tb_MidSoft_Provide model = bll.GetModel(ProvideId);
            this.txtProvideName.Text = model.ProvideName;
            this.txtProvideNumber.Text = model.ProvideNumber;
            this.txtContactName.Text = model.ContactName;
            this.txtContactType.Text = model.ContactType;
            this.txtContactTel.Text = model.ContactTel;
            this.txtContactAddress.Text = model.ContactAddress;
            this.txtContactMail.Text = model.ContactMail;
        }

        public void btnSave_Click(object sender, EventArgs e)
        {
            string strErr = "";
            if (this.txtProvideName.Text.Trim().Length == 0)
            {
                strErr += "供应商名称不能为空！\\n";
            }
            if (this.txtProvideNumber.Text.Trim().Length == 0)
            {
                strErr += "供应商编号不能为空！\\n";
            }
            if (this.txtContactName.Text.Trim().Length == 0)
            {
                strErr += "联系人不能为空！\\n";
            }
            if (this.txtContactType.Text.Trim().Length == 0)
            {
                strErr += "联系方式不能为空！\\n";
            }
            if (this.txtContactTel.Text.Trim().Length == 0)
            {
                strErr += "联系电话不能为空！\\n";
            }
            if (this.txtContactAddress.Text.Trim().Length == 0)
            {
                strErr += "联系方式不能为空！\\n";
            }
            if (this.txtContactMail.Text.Trim().Length == 0)
            {
                strErr += "联系方式不能为空！\\n";
            }

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int ProvideId = ChinaSoft.Common.Input.SetInt(Request.Params["id"]);
            string ProvideName = this.txtProvideName.Text;
            string ProvideNumber = this.txtProvideNumber.Text;
            string ContactName = this.txtContactName.Text;
            string ContactType = this.txtContactType.Text;
            string ContactTel = this.txtContactTel.Text;
            string ContactAddress = this.txtContactAddress.Text;
            string ContactMail = this.txtContactMail.Text;
            #region 添加
            ChinaSoft.BLL.BLL_tb_MidSoft_Provide bll = new ChinaSoft.BLL.BLL_tb_MidSoft_Provide();
            ChinaSoft.Model.Model_tb_MidSoft_Provide model = bll.GetModel(ProvideId);
            model.ProvideName = ProvideName;
            model.ProvideNumber = ProvideNumber;
            model.ContactName = ContactName;
            model.ContactType = ContactType;
            model.ContactTel = ContactTel;
            model.ContactAddress = ContactAddress;
            model.ContactMail = ContactMail;

            bll.Update(model);
            #endregion

            #region 添加日志
            ChinaSoft.Model.Model_tb_MidSoft_log modelLog = new ChinaSoft.Model.Model_tb_MidSoft_log();
            ChinaSoft.BLL.BLL_tb_MidSoft_log bllLog = new ChinaSoft.BLL.BLL_tb_MidSoft_log();
            modelLog.userAccount = "";
            if (Session["UserAccount"] != null && Session["UserAccount"].ToString() != "")
                modelLog.userAccount = Session["UserAccount"].ToString();
            modelLog.userName = "";
            if (Session["UserName"] != null && Session["UserName"].ToString() != "")
                modelLog.userName = Session["UserName"].ToString();
            modelLog.description = "供应商信息修改,ID=" + ProvideId;
            modelLog.LogType = 2;
            modelLog.CreateTime = DateTime.Now;
            bllLog.Add(modelLog);
            #endregion
            Response.Write("<script>alert('成功！');top.window.parent.frames.item('workspace').location.reload();window.parent.$('#DivSysiframe').dialog(\"close\");</script>");
        }
    }
}